Skip to content

Predict Times#135

Merged
mattlevine22 merged 46 commits intomainfrom
dw-ml-predict-times
Mar 20, 2026
Merged

Predict Times#135
mattlevine22 merged 46 commits intomainfrom
dw-ml-predict-times

Conversation

@DanWaxman
Copy link
Collaborator

@DanWaxman DanWaxman commented Mar 10, 2026

Addresses #50 #116

Summary

This PR introduces first-class support for predict_times-driven simulation and filter rollout across simulators and filtering integrations, with consistent output sites, shape handling, and docs/tests coverage.

  • Adds/expands simulator + filter composition so models can:
    • condition on obs_times/obs_values
    • optionally roll out trajectories at predict_times
    • expose deterministic rollout outputs (f_predicted_times, f_predicted_states, f_predicted_observations) in a consistent way.
  • Refactors simulator internals (notably BaseSimulator/DiscreteTimeSimulator/SDE/ODE flow) to better separate:
    • conditioning paths vs forward simulation paths
    • n-simulation vectorized execution vs single-trajectory conditioned execution
    • filter-rollout segmentation behavior.
  • Unifies particle-filter posterior conversion logic across integrations via shared utility code (particles_to_delta_mixtures), with standardized expected tensor shapes and cleaner backend plumbing.
  • Improves control/time validation and alignment behavior (including union-of-times handling where relevant), and clarifies edge-case behavior for missing grids.
  • Adds substantial test coverage for matrixed input combinations and shape contracts:
    • new input-matrix tests for obs_times/obs_values/predict_times
    • predictive shape tests for num_samples and n_simulations
    • updated smoke/science/model tests to reflect new rollout/output conventions.
  • Updates API docs/tutorials to clearly explain:
    • when to use obs_times vs predict_times
    • required pairing of obs_times and obs_values
    • deterministic site names and resulting output shapes.
  • Updates notebooks with concrete predict_times examples, including:
    • rollout/forecasting after filtering
    • back-fill interpolation/reconstruction between observation times.

Motivation

Previously, prediction-time rollout and simulator/filter interoperability were harder to reason about and less uniformly tested/documented, especially around mixed obs_times/predict_times workflows and shape conventions.
This PR makes that behavior explicit, consistent, and verifiable: users can condition and forecast in one coherent interface, while downstream analysis/tests/docs rely on stable site naming and tensor shape contracts.

Performance

This solution entails some additional checks + building and storing filtered distributions at all obs_times points during a sample statement. In our experiments, this causes a ~20% overhead. This is non-negligible, but seems worth it to have the prediction feature.

@DanWaxman DanWaxman changed the title Predict Times [WIP] Predict Times Mar 17, 2026
@DanWaxman
Copy link
Collaborator Author

This looks great to a first read! I'll read in more depth tomorrow. In the mean time, we should write up & update the PR description. This should be squash & merged, so the description should be fairly complete as to sufficiently describe the progress & design choices on its own.

@DanWaxman DanWaxman requested a review from mattlevine22 March 17, 2026 13:33
Comment on lines 92 to 97
"""
Validate that ctrl_times/ctrl_values align with obs_times if provided.

Raises:
ValueError: If control times length doesn't match observation times length.
"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain all the rules that are being tested

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@DanWaxman
Copy link
Collaborator Author

@mattlevine22 left feedback

Copy link
Collaborator

@mattlevine22 mattlevine22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated based on @DanWaxman's feedback.

Summary

This PR introduces first-class support for predict_times-driven simulation and filter rollout across simulators and filtering integrations, with consistent output sites, shape handling, and docs/tests coverage.

  • Adds/expands simulator + filter composition so models can:
    • condition on obs_times/obs_values
    • optionally roll out trajectories at predict_times
    • expose deterministic rollout outputs (f_predicted_times, f_predicted_states, f_predicted_observations) in a consistent way.
  • Refactors simulator internals (notably BaseSimulator/DiscreteTimeSimulator/SDE/ODE flow) to better separate:
    • conditioning paths vs forward simulation paths
    • n-simulation vectorized execution vs single-trajectory conditioned execution
    • filter-rollout segmentation behavior.
  • Unifies particle-filter posterior conversion logic across integrations via shared utility code (particles_to_delta_mixtures), with standardized expected tensor shapes and cleaner backend plumbing.
  • Improves control/time validation and alignment behavior (including union-of-times handling where relevant), and clarifies edge-case behavior for missing grids.
  • Adds substantial test coverage for matrixed input combinations and shape contracts:
    • new input-matrix tests for obs_times/obs_values/predict_times
    • predictive shape tests for num_samples and n_simulations
    • updated smoke/science/model tests to reflect new rollout/output conventions.
  • Updates API docs/tutorials to clearly explain:
    • when to use obs_times vs predict_times
    • required pairing of obs_times and obs_values
    • deterministic site names and resulting output shapes.
  • Updates notebooks with concrete predict_times examples, including:
    • rollout/forecasting after filtering
    • back-fill interpolation/reconstruction between observation times.

Motivation

Before this PR, we did not expose predict_times as a supported workflow.
That meant users could not cleanly ask for trajectories at arbitrary prediction times (for rollout, interpolation/back-fill, or post-filter forecasting) within the standard simulator/filter interface.

This PR adds that capability and makes the behavior explicit, tested, and documented.

@DanWaxman
Copy link
Collaborator Author

Great, thanks! There's one or two remaining comments open, then I think it's good to merge!!

* faster test strategy

* simplify num samples

* update blackjax mcmc notebook

* updating notebooks; didnt re-run GP, but should work

* re-ran sde non-gaussian notebook

* reran profile mll nb
@DanWaxman
Copy link
Collaborator Author

I added to the description. As long as tests pass, this seems okay to me.


Performance

This solution entails some additional checks + building and storing filtered distributions at all obs_times points during a sample statement. In our experiments, this causes a ~20% overhead. This is non-negligible, but seems worth it to have the prediction feature.

Copy link
Collaborator

@mattlevine22 mattlevine22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

big steps

@mattlevine22 mattlevine22 merged commit fd95191 into main Mar 20, 2026
2 checks passed
@DanWaxman DanWaxman deleted the dw-ml-predict-times branch March 23, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support non-filtered predict_times for trajectory-based evaluation Forecast evaluations will need a posterior "rollout" mode

2 participants